// simple fragment shader

// 'time' contains seconds since the program was linked.
varying vec3 N, V, L;
uniform sampler2D texture; 

vec4 light(vec3 N, vec3 V, vec3 L)
{
	N=normalize(N); V=normalize(V); L=normalize(L);
	vec3 R = normalize( 2.0*dot(N,L)*N-L );
	float NdotL = max( 0.0, dot( N,L ) );
	float RdotV = max( 0.0, dot( R,V ) );
	float Idiff = NdotL;
	float Ispec = pow( RdotV, gl_FrontMaterial.shininess );
	return
	gl_FrontMaterial.emission +
	gl_FrontMaterial.ambient * gl_LightModel.ambient +
	gl_FrontMaterial.ambient * gl_LightSource[1].ambient +
	gl_FrontMaterial.diffuse * gl_LightSource[1].diffuse * Idiff+
	gl_FrontMaterial.specular * gl_LightSource[1].specular * Ispec;
}



void main()
{
	gl_FragColor = texture2D(texture, vec2(gl_TexCoord[0]))*light(N,V,L);
}
